<?php
class Pais extends CI_Controller{

    var $url ='pais';

    function __construct(){
        parent::__construct();
        //$this->lang->load('empresa/datos');
        //$this->load->library('form_validation');
    }

    function autocomplete(){
		$term      =$this->input->post('term');
		$terme     =$this->db->escape('%'.$term.'%');
		$termed    =$this->db->escape($term.'%');

		$query  ="SELECT pais.*, pais.nombre label
				FROM pais
				WHERE nombre LIKE $terme
				ORDER BY nombre NOT LIKE $termed,nombre ";

		$mSQL   = $this->db->query($query);
		$arreglo= $mSQL->result_array($query);

		foreach($arreglo as $key=>$value)
			foreach($value as $key2=>$value2)
				$arreglo[$key][$key2] = ($value2);

		header ('Content-type: text/html; charset=utf-8');
		echo json_encode($arreglo);


	}
}
?>
